<?php

/**
 * model_special
 */

class Model_special extends YOU {

	public function __construct()
	{
		parent::__construct();
	}

	/** 读取成配置 **/
	public function getIni()
	{
		$special_lists = $this->getAll();
		foreach ($special_lists as $key => $value){
			$special[$value['special_id']] = $value['special_name'];
		}

		return $special;
	}

	/** 读取列表 **/
	public function getAll($field = "*")
	{
		$special_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_special` ");

		return $special_lists;
	}	
	
	/** 根据class_id得到列表 **/
	public function getList($class_id)
	{
		// 得到年级id
		$class_data = $this->db->fetchRow("SELECT grade_id FROM `tbl_class` WHERE class_id='{$class_id}' ");
		$grade_id = $class_data['grade_id'];
		
		// 查出所有的特殊课堂
		$special_lists = $this->getAll();

		$data = array();
		foreach ($special_lists as $key => $value){
			if ($value['special_type'] == "school"){
				$data[] = $value;
			}
			if ($value['special_type'] == "grade" && $value['type_id']==$grade_id){
				$data[] = $value;
			}
			if ($value['special_type'] == "class" && $value['type_id']==$class_id){
				$data[] = $value;
			}			
		}

		return $data;
	}


}



?>